var loginHandler = function() {
	function createWindow(loginPanel) {
	    return new Ext.Window({
	        layout:'fit',
	        width:300,
	        height:150,
	        closable: false,
	        resizable: false,
	        plain: true,
	        border: false,
	        modal: true,
	        items: [loginPanel]
		});
	};
	
	function createLoginPanel() {
	    var loginPanel =  new Ext.FormPanel({ 
	        labelWidth:80,
	        url:'/PictureCentral/authentication/login', 
	        frame:true, 
	        title:'Please Login', 
	        defaultType:'textfield',
		    monitorValid:true,
	        items:[{ 
	                fieldLabel:'User ID', 
	                name:'login', 
	                allowBlank:false 
	            },{ 
	                fieldLabel:'Password', 
	                name:'password', 
	                inputType:'password', 
	                allowBlank:false 
	            }],
      	        buttons:[
                    new Ext.Button({
            			text:'Login',
            			tabIndex:0,
            			formBind: true,	 
            			handler:function(){ 
            		    	loginPanel.getForm().submit({ 
            		    		method:'POST', 
            		    		success: function(){
            		    		    window.location = "/PictureCentral/";
            		    	    },
            		    		failure:function(form, action){ 
            		    			if(action.failureType.indexOf('server') == 0){ 
            		    				obj = Ext.util.JSON.decode(action.response.responseText); 
            		    				Ext.Msg.alert('Login Failed!', obj.errors.reason); 
            		    			}else{ 
            		    				Ext.Msg.alert('Warning!', 'Authentication server is unreachable : ' + action.response.responseText); 
            		    			} 
            		    			loginPanel.getForm().reset(); 
                            	} 
            		    	}); 
                    	} 
            		}),
            		createSetupUserButton()
      	        ] 
	    });
	    return loginPanel;
	};

	function createSetupUserButton() {
		return new Ext.Button({
			text:'New User',
			handler: function(){
				window.location = "/PictureCentral/authentication/create";
			}
		});
	}
	return {
		loginWindow : function() {
		   var loginWin =createWindow(createLoginPanel());
		   loginWin.show();		   
	    }		
	};	
}();

var authentication = {};
authentication.create = function() {
	
}();

